package com.slipper.codeless.controller;

import com.slipper.system.codeless.bo.MobileBO;
import com.slipper.system.codeless.bo.MobilePageBO;
import com.slipper.system.codeless.service.MobilePageService;
import com.slipper.system.codeless.service.MobileService;
import com.slipper.util.ResultUtil;
import com.slipper.util.Tool;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobile")
public class MobileApiController {
    @Resource
    private MobileService mobileService;
    @Resource
    private MobilePageService mobilePageService;

    @PostMapping(value = "/queryBy")
    public String queryBy(@RequestBody MobileBO bo) {
        if (Tool.isBlank(bo.getId())) return ResultUtil.failureResult("参数不正确！");

        MobileBO mobile = mobileService.queryBy(bo.getId());
        if (mobile == null) return ResultUtil.failureResult("参数不正确！");

        MobilePageBO mobilePageQO = new MobilePageBO();
        mobilePageQO.setMobileId(mobile.getId());
        mobilePageQO.setType(MobilePageBO.TYPE_PAGE);
        mobile.setPageList(mobilePageService.queryList(mobilePageQO));
        return ResultUtil.successResult(mobile);
    }
}
